package com.usian.controller;

import com.usian.feign.CotnentServiceFeign;
import com.usian.pojo.TbContent;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/content")
public class ContentController {
    @Autowired
    private CotnentServiceFeign cotnentServiceFeign;

    /**
     * @return com.usian.utils.Result
     * @Author 韩耀东
     * @Description //TODO 查询分类内容
     * @Date 2021/1/8 10:36
     * @Param [page, rows, categoryId]
     **/
    @RequestMapping("/selectTbContentAllByCategoryId")
    public Result selectTbContentAllByCategoryId(@RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "5") Integer rows,
                                                 Long categoryId) {
        PageResult pageResult = cotnentServiceFeign.selectTbContentAllByCategoryId(page, rows, categoryId);
        if (pageResult != null && pageResult.getResult().size() > 0) {
            return Result.ok(pageResult);
        }
        return Result.error("查无结果");
    }

    @RequestMapping("/insertTbContent")
    public Result insertTbContent(TbContent tbContent) {
        Integer status = cotnentServiceFeign.insertTbContent(tbContent);
        if (status == 0)
            return Result.error("添加失败");
        return Result.ok();
    }

    @RequestMapping("/deleteContentByIds")
    public Result deleteContentByIds(Long ids){
        Integer status = cotnentServiceFeign.deleteContentByIds(ids);
        if (status == 0)
            return Result.error("删除失败");
        return Result.ok();
    }
}    